<template>
  <a-modal
    :visible="visible"
    title="审核"
    cancelText="拒绝"
    okText="同意"
    @ok="submit"
    @cancel="cancel"
  >
    <template #footer>
      <a-button  @click="cancel" >关闭</a-button>
      <a-button type="primary" danger @click="applyRefuseClick">驳回</a-button>
      <a-button type="primary" @click="submit">同意</a-button>
    </template>

    <a-form
       ref="formRef"
      :model="formState"
      :rules="formRules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-item ref="goodsName" label="物品名称" name="goodsName">
        <a-input v-model:value="formState.goodsName" disabled="true" />
      </a-form-item>
      <a-form-item ref="applicationNumber" label="申请数量" name="applicationNumber">
        <a-input type="number" v-model:value="formState.applicationNumber"  disabled="true"/>
      </a-form-item>
      <a-form-item ref="applicationNumber" label="申请人" name="nickname">
        <a-input type="text" v-model:value="formState.nickname" disabled="true"  />
      </a-form-item>
      <a-form-item ref="application" label="申请用途" name="application">
        <a-input v-model:value="formState.application"  disabled="true"/>
      </a-form-item>
      <a-form-item label="申请时间" name="applicationTime">
        <a-input type="datetime" v-model:value="formState.applicationTime" disabled="true"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import {createVNode, defineComponent, reactive, ref, toRaw, watch} from "vue";
import {message, modal} from "_ant-design-vue@2.2.8@ant-design-vue";
import {apply, applyAudit, applyRefuse} from "@/api/module/application";
import {ExclamationCircleOutlined} from "_@ant-design_icons-vue@6.1.0@@ant-design/icons-vue";
export default defineComponent({
  props: {
    visible: {
      type: Boolean,
    },
    record: {
      type: Object,
    }
  },
  emit: ["close"],
  setup(props, context) {

    const formRef = ref();

    const formState = reactive({});

    watch(props, (props) => {
      console.log("props++--++--",props.record)
        formState.id = props.record.id
        formState.nickname = props.record.nickname
        formState.goodsName = props.record.goodsName
        formState.application = props.record.application
        formState.applicationTime = props.record.applicationTime
        formState.applicationNumber = props.record.applicationNumber
    })

    const formRules = { };


    const submit = (e) => {
      applyAudit({"id":formState.id}).then((response) => {
        if(response.success){
          message.success({content: "审核成功", duration: 1})
          cancel();
        }else{
          message.error({content: "审核失败", duration: 1})
          cancel();
        }
      })
    };


    const applyRefuseClick = (e) => {
      applyRefuse({"id":formState.id}).then((response) => {
        if(response.success){
          message.success({content: "拒绝成功", duration: 1})
          cancel();
        }else{
          message.error({content: response.msg, duration: 1})
          cancel();
        }
      })
    };
    const cancel = (e) => {
      formRef.value.resetFields();
      context.emit("close", false);
    };

    return {
      submit,
      applyRefuseClick,
      cancel,
      formRef,
      formState,
      formRules,

      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
    };
  },
});
</script>
